package com.topisv.tms.service.notice;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.topisv.tms.entity.QueryParamHolder;
import com.topisv.tms.entity.notice.Notice;
import com.topisv.tms.entity.notice.NoticeReader;
import com.topisv.tms.repository.notice.NoticeDao;
import com.topisv.tms.repository.notice.NoticeReaderDao;
import com.topisv.tms.service.base.BaseService;

//Spring Bean的标识.
@Component
// 默认将类中的所有public函数纳入事务管理.
@Transactional(readOnly = true)
public class NoticeService extends BaseService{

	@Autowired
	private NoticeDao noticeDao;
	@Autowired
	private NoticeReaderDao noticeReaderDao ; 
	
	
	public List<Notice> findByStatus(String status) {
		return noticeDao.findByStatus(status);
	}
	
	public Notice findById(Long id) {
		return noticeDao.findById(id);
	}
	public void updateAll() {
		noticeDao.update();
	}
	public void updateById(Long id) {
		noticeDao.update(id);
	}
	
	@Transactional(readOnly = false)
	public void saveNotice(Notice entity) {
		noticeDao.save(entity);
	}
	@Transactional(readOnly = false)
	public void deleteNotice(Long id) {
		noticeDao.delete(id);
	}
	
	public Page<Notice> getNotice(QueryParamHolder paramHolder) {
		return findByJson(paramHolder, noticeDao, Notice.class);
	}
	
	public NoticeDao getNoticeDao() {
		return noticeDao;
	}
	@Autowired
	public void setNoticeDao(NoticeDao noticeDao) {
		this.noticeDao = noticeDao;
	}
	
	public NoticeReader findByJobuuid(String jobuuid){
		return noticeReaderDao.findByJobuuid(jobuuid) ;
	}
	public NoticeReader findByJobuuidAndId(String jobuuid,String noticeId){
		return noticeReaderDao.findByJobuuidAndId(jobuuid,noticeId) ;
	}
	
	@Transactional(readOnly = false)
	public void saveNoticeReader(NoticeReader entity) {
		noticeReaderDao.save(entity);
	}
	   /**
     * 根据Jobuuid查询未读的置顶消息
     * @param jobuuid
     * @return [参数说明]
     * 
     * @return List<Notice> [返回类型说明]
     * @exception throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    public List<Notice> findByJobuuidNoReaderNotice(String jobuuid) {
        return noticeDao.findByJobuuidNoReaderNotice(jobuuid);
    }
}
